package com.itheima.health.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Lakers;
import com.itheima.health.service.LakersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/lakers")
@Slf4j
public class LakersController {
    @Reference
    private LakersService lakersService;

    //分页查询
    @GetMapping("/findPage")
    public Result findPage(QueryPageBean queryPageBean){
        PageResult pageResult = lakersService.pageQuery(queryPageBean);
        return new Result(true, MessageConst.ACTION_SUCCESS,pageResult);
    }
    //新增权限
    @RequestMapping("/add")
    public Result add(@RequestBody Lakers lakers){
        log.info("[权限管理-新增]data:{}",lakers);
        lakersService.add(lakers);
        return new Result(true,MessageConst.ADD_PERMISSION_SUCCESS);
    }
    //根据id删除权限
    @RequestMapping("/delete")
    public Result deleteById(Integer id){
        log.info("[权限管理-根据id删除]id:{}",id);
        lakersService.deleteById(id);
        return new Result(true,MessageConst.DELETE_PERMISSION_SUCCESS);
    }
    //根据id查询
    @RequestMapping("/findById")
    public Result findById(Integer id){
        log.info("[权限管理-根据ID查询]id:{}", id);
        Lakers lakers=lakersService.findById(id);
        return new Result(true,MessageConst.QUERY_PERMISSION_SUCCESS,lakers);
    }
    //编辑权限
    @RequestMapping("/edit")
    public Result edit(@RequestBody Lakers lakers){
        log.info("[权限管理-编辑]data:", lakers);
        lakersService.edit(lakers);
        return new Result(true,MessageConst.UPDATE_PERMISSION_SUCCESS);
    }
}
